package com.ys.erp.entity.data.bean;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lwj
 * @date 2023/4/28
 */
    
@Data
@TableName(value = "t_order_goods")
public class OrderGoods {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.INPUT)
    private Long id;

    /**
     * 订单id
     */
    @TableField(value = "order_id")
    private Long orderId;

    @TableField(value = "user_id")
    private Long userId;

    /**
     * 商品id
     */
    @TableField(value = "goods_id")
    private Long goodsId;

    /**
     * 商品图片
     */
    @TableField(value = "goods_pic")
    private String goodsPic;

    /**
     * 商品名字
     */
    @TableField(value = "goods_name")
    private String goodsName;

    /**
     * 商品规格
     */
    @TableField(value = "goods_specs")
    private String goodsSpecs;

    /**
     * 小计，单位分
     */
    @TableField(value = "subtotal")
    private Long subtotal;

    @TableField(value = "ys_pulse_money")
    private Long ysPulseMoney;

    /**
     * 优惠金额,单位分
     */
    @TableField(value = "discount_money")
    private Long discountMoney;

    @TableField(value = "delivery_money")
    private Long deliveryMoney;

    @TableField(value = "delivery_cost")
    private Long deliveryCost;

    /**
     * 数量
     */
    @TableField(value = "goods_count")
    private Integer goodsCount;

    @TableField(value = "goods_weight")
    private Integer goodsWeight;

    @TableField(value = "goods_price")
    private Long goodsPrice;

    @TableField(value = "goods_cost")
    private Long goodsCost;

    @TableField(value = "is_send_goods")
    private Integer isSendGoods;

    @TableField(value = "jst_uploaded")
    private Integer jstUploaded;

    @TableField(value = "jst_order_id")
    private String jstOrderId;

    @TableField(value = "bus_remark")
    private String busRemark;

    @TableField(value = "express_name")
    @Deprecated
    private String expressName;

    @TableField(value = "express_id")
    private String expressId;

    @TableField(value = "send_goods_time")
    private LocalDateTime sendGoodsTime;

    @TableField(value = "is_after_sale")
    private Integer isAfterSale = 0;

    @TableField(value = "after_sale_time")
    private LocalDateTime afterSaleTime;

    @TableField(value = "after_sale_status")
    private Integer afterSaleStatus;

    @TableField(value = "is_agree_after_sale")
    private Integer isAgreeAfterSale;

    @TableField(value = "after_sale_num")
    private Integer afterSaleNum = 0;

    @TableField(value = "is_gift")
    private Integer isGift;

    @TableField(value = "ys_money")
    private Long ysMoney;

    @TableField(value = "wx_money")
    private Long wxMoney;

    /**
     * 是否删除0 否 1是
     */
    @TableField(value = "is_delete")
    private Integer isDelete;

    @TableField(value = "version")
    @Version
    private Integer version;

    @TableField(value = "create_time")
    private LocalDateTime createTime;

    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;

    public String getSpecsDes() {
        List<KeyValueDTO> specsList = JSONArray.parseArray(this.getGoodsSpecs(), KeyValueDTO.class);
        return specsList.stream().map(it -> {
            return it.getKey() + ": " + it.getValue();
        }).collect(Collectors.joining(","));
    }

    @Data
    @Accessors(chain = true)
    public static class KeyValueDTO {

        private String key;

        private String value;

    }


}